﻿using System;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
using QuanLyTuyenSinh.Base;

namespace QuanLyTuyenSinh.PresentationLayer.Components
{
    public partial class frmDanhphach : Form
    {
       private SqlConnection Conn;
        private string Sqlx;
        public frmDanhphach()
        {
            InitializeComponent();
        }

        private void frmDanhphach_Load(object sender, EventArgs e)
        {
            try
            {
                //Conn = ConnectData.Getcon();
                //Conn.Open();
                //comboKhoithi.DataSource = monthibus.GetKhoithiUngVoiNganhHoc();
                //comboKhoithi.DisplayMember = "Khoithi";
                //comboKhoithi.ValueMember = "Khoithi";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private void Updatehs(string SBD,string Mon,string phach)
        {
            try
            {
                //Conn = ConnectData.Getcon();
                //Conn.Open();
                //string sqlk = "Update TSSBD set Phach"+Mon+"='"+phach+"' where SBD='" + SBD + "' and Khoithi='"+comboKhoithi.Text.Trim()+"'";
                //SqlCommand cmd = new SqlCommand(sqlk, Conn);
                //cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        //DataTable GetByAll()
        //{
        //    Sqlx = "select str(row_number() over(order by TSSBD.SBD)) as 'STT',SBD,TuiM1,TuiM2,TuiM3 from TSSBD where Khoithi='" + comboKhoithi.Text + "'";
        //    SqlCommand cmd = new SqlCommand(Sqlx, ConnectData.Getcon());
        //    return ConnectData.GetTable(cmd);
        //}
        private void cmdDanhphach_Click(object sender, EventArgs e)
        {
            //try
            //{
            //    if (checkBoxMon1.Checked == true)
            //    {
            //        int dem = 200;
            //        foreach (DataRow row in GetByAll().Rows)
            //        {
            //            string Id = row["SBD"].ToString();
            //            Updatehs(Id, "M1", dem.ToString());
            //            dem++;
            //        }
            //        MessageBox.Show("Đánh phách cho môn 1 của khối " + comboKhoithi.Text + " thành công!");
            //        dem = 320;
            //    }
            //    else if (checkBoxMon2.Checked == true)
            //    {
            //        int dem1 = 139;
            //        foreach (DataRow row in GetByAll().Rows)
            //        {
            //            string Id = row["SBD"].ToString();
            //            Updatehs(Id, "M2", dem1.ToString());
            //            dem1++;
            //        }
            //        MessageBox.Show("Đánh phách cho môn 2 của khối " + comboKhoithi.Text + " thành công!");
            //        dem1 = 302;
            //    }
            //    else if (checkBoxMon3.Checked == true)
            //    {
            //        int dem1 = 500;
            //        foreach (DataRow row in GetByAll().Rows)
            //        {
            //            string Id = row["SBD"].ToString();
            //            Updatehs(Id, "M3", dem1.ToString());
            //            dem1++;
            //        }
            //        MessageBox.Show("Đánh phách cho môn 3 của khối " + comboKhoithi.Text + " thành công!");
            //       dem1 = 1000;
            //    }
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.ToString());
           // }
        }

     private void comboKhoithi_SelectedIndexChanged(object sender, EventArgs e)
        {
            checkBoxMon3.Checked = false;
            checkBoxMon2.Checked = false;
            checkBoxMon1.Checked = false;
            try
            {
                //DataGridPhach.DataSource = thisinhbus.LoadDSTui(comboKhoithi.Text.Trim());
                //DataGridPhach.Columns[0].HeaderText = "STT";
                //DataGridPhach.Columns[1].HeaderText = "SBD";
                //DataGridPhach.Columns[2].HeaderText = "Phòng thi";
                //DataGridPhach.Columns[3].HeaderText = "Túi M1";
                //DataGridPhach.Columns[4].HeaderText = "Túi M2";
                //DataGridPhach.Columns[5].HeaderText = "Túi M3";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}